VectorScale2d and VectorScale3d
in genMath.lib
Vector Functions Function List by Category Alphabetical Function List
int VectorScale2d(
float *VectorA,
// pointer to vector A array
float Scale,
// scale factor
float *ScaledVector)
// pointer to result vector array
int VectorScale3d(
float *VectorA,
// pointer to vector A array
float Scale,
// scale factor
float *ScaledVector) //
pointer to result vector array
Functions to a 2-d or 3-d vector by a scalar:
ScaledVector(i) = c * a(i)
Calls
to these routines will be faster than calls to genVectorScale,
for two reasons.
First, the dimension does not have to be passed as a parameter, and second, the
loops
in these routines are unrolled.
Note that by using multiple calls, these routines can be used to scale
larger dimension vectors, if care is taken in the passing of the pointers.
The
return code is errno, defined in the C standard library (math.h). This is
an integer value
for math errors.
Sample Application:
/////////// splVScal.c for VectorScale3d Library Function ////////////
// // //
// For this sample, a 3-d vector is used. The vector is in //
// array a and the scaled vector is returned into array b //
// //
// Use of VectorScale2d is similar. //
// //
//////////////////////////////////////////////////////////////////////
//////////////////////////// INCLUDES ////////////////////////////////
#include "stdio.h"
#include "genMath.h"
////////////////////////////// MAIN //////////////////////////////////
void main()
{
//local declarations
//integers
int retcode; // return code for call to VectorScale
int i; // counter to display result
//floats
float a[3]; // vector
float b[3]; // scaled vector
float c; // scale factor
//character strings
char ch; // input string to exit
//intialize the A and B vectors
a[0] = (float)1.234;
a[1] = (float)-.678;
a[2] = (float)10.3;
//scale the vector
retcode = VectorScale3d(a,b,&c);
//display the result
printf("%s", "Scaled Vector: \n\n");
for(i = 0; i<3; ++i){
printf("%s%d%s%f%s","b[",i,"] = ", b[i],"\n")};
}
//display closing message and wait for <enter> before exiting
printf("\n\nPress <Enter> to end");
scanf("%c", &ch);
} // End Main
/////////////////////////////// End splVScal.c ///////////////////////